function search_Lianghao(i){
	switch(i){
		case 1:
			var search_Lh = document.getElementsByClassName("lianghao-detail");
			search_Lh[0].style.display = "block";
			break;
		case 2:
			var search_Lh = document.getElementsByClassName("lianghao-detail");
			search_Lh[0].style.display = "none";
			break;
		default:
			alert("数据错误");
			break;
	}
}
function input_value(){
	$('#lianghao-key').bind('input propertychange',function(){
		var length = $('#lianghao-key').val().length;
		if(length > 0){
			$('#searchs').css("display","none");
			console.log(length+"a");
		}else{
			$('#searchs').css("display","inline");
			console.log(length+"b");
		}
	});
}
function search_lh(){
	var lh_key = document.getElementById("lianghao-key");
	window.open("//haoma.qq.com/shop.html#num=" + lh_key.value);
}
function language_ch(g){
	switch(g){
		case 1:
			var language_Choose = document.getElementById("language-choose");
			language_Choose.style.display = "block";
			var down =  document.getElementsByName("down");
			var up   =  document.getElementsByName("up");
			down[0].style.display = "none";
			up[0].style.display	  =	"inline";
			break;
		case 2:
			var language_Choose = document.getElementById("language-choose");
			language_Choose.style.display = "none";
			var down =  document.getElementsByName("down");
			var up   =  document.getElementsByName("up");
			down[0].style.display = "inline";
			up[0].style.display	  =	"none";
			break;
		default:
			alert("数据错误");
			break;
	}
}
function check_ed(h){
	switch(h){
		case 1:
			var check = document.getElementsByName("check");
			check[0].style.display="inline";
			var checked = document.getElementsByName("checked");
			checked[0].style.display="none";
			break;
		case 2:
			var check = document.getElementsByName("check");
			check[0].style.display="none";
			var checked = document.getElementsByName("checked");
			checked[0].style.display="inline";
			break;
		case 3:
			var check = document.getElementsByName("check");
			check[1].style.display="inline";
			var checked = document.getElementsByName("checked");
			checked[1].style.display="none";
			break;
		case 4:
			var check = document.getElementsByName("check");
			check[1].style.display="none";
			var checked = document.getElementsByName("checked");
			checked[1].style.display="inline";
			break;
		default:
			alert("数据错误");
			break;
	}
}
function rule_three(j){
	switch(j){
		case 1:
			var down =  document.getElementsByName("down");
			var up   =  document.getElementsByName("up");
			down[1].style.display = "none";
			up[1].style.display	  =	"inline";
			var agreement = document.getElementsByClassName("agreement-list");
			agreement[0].style.visibility = "visible";
			break;
		case 2:
			var down =  document.getElementsByName("down");
			var up   =  document.getElementsByName("up");
			down[1].style.display = "inline";
			up[1].style.display	  =	"none";
			var agreement = document.getElementsByClassName("agreement-list");
			agreement[0].style.visibility = "hidden";
			break;
		default:
			alert("数据错误");
			break;
	}
}
/**
 * form表单检查  Verifivation:验证 
 * 思路:
 * 	1.初次进入页面所以error提示不显示
 * 	2.输入框获取焦点，需要进行判断，
 * 		a.只点击一个输入框，当输入框失去焦点时，判断输入框内容是否改变	
 * 			(1).改变：判断是否为空字符串，空字符串显示
 * 			(2).没改变:显示error提示
 *		b.两个输入框都点击，但是输入框失去焦点时,判断是否两个输入框都失去焦点
 * 			(1).失去一个:做a判断，显示对应error或者不显示
 * 			(2).失去两个:做a判断，两个都为空显示
 *  onblur 事件会在对象失去焦点时发生。
 * 	onfocus 事件会在对象获得焦点时发生。
 * */

/**
 * 
 * @param {Object} index 下标
 * @param {Object} flag 对象失去焦点0 获得焦点1 标识符
 */
/*
 * 输入框值长度
 */

var pwdIsNull = false;
var nameIsNull = false;
var phoneIsNull = false;
var pwdLength = false;
var pwdFormat = false;

function VerificationContent(index,flag){
	
	//昵称//密码
	var nameAndPWD = document.getElementsByClassName("nickname-password")[index];
	var nameAndPWDValue = nameAndPWD.value;
	//错误提示
	var errors = document.getElementsByClassName("error-tips")[index];
	//密码判断
	var passwordTipsGroup = document.getElementsByClassName("password-tips-group")[0];
	//label
	var inputPlaceholder = document.getElementsByClassName('input-placeholder')[index];
	//
	var sendSms = document.getElementById("send-sms");
	

	 //实时监听username  input 的值
	listenNameInput();
	
	// 实时监听password  input 的值
	listenPWDInput();
	
	// 实时监听phone  input 的值
	listenPhoneInput();
	
	listenCodeInput();
	
	//失去焦点
	if(flag== 0){
		//console.log("1");
		//判断input是否为空
		if(nameAndPWDValue == "" && nameAndPWDValue.length == 0 ){
			//console.log("2");
			passwordTipsGroup.style.display = "none";
			//console.log("aaa")
			switch(index){
				case 0:
					errors.innerHTML = "昵称不可以为空";
					errors.style.display = "block";
					//input 边框变成红色
					nameAndPWD.style.borderColor="red";
					break;
				case 1:
					
					errors.innerHTML = "密码不可以为空";
					errors.style.display = "block";
					//input 边框变成红色
					nameAndPWD.style.borderColor="red";
					break;
				case 2:
					
					$("#sms-div-show").css("display","none");
					
					break;
				
			}
					
			
			//不为空 判断输入的昵称是否符合标准
		}else if(nameAndPWDValue.length > 0){
			
			//昵称包含空格
			if(nameIsNull && index == 0){
				//console.log("index:"+index);
				errors.innerHTML = "昵称不能包含空格";
				errors.style.display = "block";
				nameAndPWD.style.borderColor="red";
				
			}
			if(!nameIsNull && index == 0){
				queryUser();
				$.ajax({
					type:"post",
					url:"queryUserName",
					data:"nameAndPWDValue="+nameAndPWDValue,
					success:function(data){
						console.log("queryUser ok");
						if(data=="true"){
							userExist();
							nameAndPWD.value = "";
						}
						
					}
			});
			}
			
			if(!phoneIsNull && index == 2){
				
				getRanNum();
				
			}
			if(phoneIsNull && index == 2){
				//console.log("index:"+index);
				$('#input-tips-wrap').html('手机号码格式不正确') ;
				$('#input-tips-wrap').css("color",'red');
				sendSms.style.borderColor = "#ccc";
				sendSms.style.backgroundColor = "#ccc";
				sendSms.style.backgroundImage = "linear-gradient(0deg, #ccc, #ccc)";
				//input 边框变成红色
				nameAndPWD.style.borderColor="red";
			}
				
			
			if(pwdLength  && pwdFormat && pwdIsNull && index == 1){
				//console.log("index:"+index);
				errors.innerHTML = "密码不能包含空格";
				passwordTipsGroup.style.display = "none";
				errors.style.display = "block";
				nameAndPWD.style.borderColor="red";
				
			}
			
			if(!pwdLength  && !pwdFormat && pwdIsNull && index == 1){
				//console.log("index:"+index);
				errors.innerHTML = "密码不能包含空格";
				passwordTipsGroup.style.display = "none";
				errors.style.display = "block";
				nameAndPWD.style.borderColor="red";
				
			}

			
			if(pwdLength  && pwdFormat && !pwdIsNull && index == 1){
				//console.log("index:"+index);
				errors.innerHTML = "长度为8-16个字符";
				passwordTipsGroup.style.display = "none";
				errors.style.display = "block";
				nameAndPWD.style.borderColor="red";
				
			}
			if(!pwdLength  && pwdFormat && !pwdIsNull && index == 1){
				//console.log("index:"+index);
				errors.innerHTML = "必须包含字母、数字、符号中至少2种";
				passwordTipsGroup.style.display = "none";
				errors.style.display = "block";
				nameAndPWD.style.borderColor="red";
				
			}
			console.log(phoneIsNull);
			if(pwdLength  && !pwdFormat && !pwdIsNull && index == 1){
				//console.log("index:"+index);
				errors.innerHTML = "长度为8-16个字符";
				passwordTipsGroup.style.display = "none";
				errors.style.display = "block";
				nameAndPWD.style.borderColor="red";
				
			}
			
		}
		//得到焦点
	}else if(flag == 1){

			//下标==1 密码项
		if(index == 1){
			
			nameAndPWD.style.borderColor="#aaa";
			passwordTipsGroup.style.display = "block";
			errors.style.display = "none";
			//密码包含空格
			
		}else if(index == 0){
			
			nameAndPWD.style.borderColor="#aaa";
			passwordTipsGroup.style.display = "none";
			errors.style.display = "none";
			
		}else if(index == 2){
			nameAndPWD.style.borderColor="#aaa";
			$('#input-tips-wrap').html('可通过该手机号找回密码') ;
			$("#input-tips-wrap").css("color","#999");
			errors.style.display = 'none';
			$("#sms-div-show").css("display","block");
			
			console.log("#3083ff"+phoneIsNull);
			sendSms.style.borderColor = "#3083ff";
			sendSms.style.backgroundColor = "#3487ff";
			sendSms.style.backgroundImage = "linear-gradient(0deg, #398bff, #3083ff)";
		
		}
		
	}
	
}


function listenPWDInput(){
	
	//验证密码是否符合标准 
	var pwdTips = document.getElementsByClassName("password-tips");
	
	$('#password').bind('input propertychange',function(){
		
		var values =  $('#password').val();
		var length = values.length;
		if(length > 0){
		
			$('#password-tips').css("display","none");
			//存在空格 跟换图片
			
				if(values.indexOf(" ") != -1){
					pwdTips[0].style.backgroundImage = 'url(img/info@2x.png)';
						pwdIsNull = true;
				}else{
						pwdIsNull = false;
				}
			//长度必须大于8小于16
			
				if(values.length>8 && values.length < 16){
					pwdTips[1].style.backgroundImage = 'url(img/green@2x.png)';	
					pwdLength = false;

				}else{
					pwdTips[1].style.backgroundImage = 'url(img/info@2x.png)';
					pwdLength = true;
					
				}
			
				//正则表达式(/(?!^[0-9]+$)(?!^[A-z]+$)(?!^[^A-z0-9]+$)^.{6,16}$/)
				var reg = /(?!^[0-9]+$)(?!^[A-z]+$)(?!^[^A-z0-9]+$)^.{8,16}$/
				if(reg.test(values)){
					pwdTips[2].style.backgroundImage = 'url(img/green@2x.png)';
					pwdFormat  =false;
				
				}else{
					pwdTips[2].style.backgroundImage = 'url(img/info@2x.png)';
					pwdFormat = true;
				}
				//console.log("pwdIsNull=="+pwdIsNull+"\n"+"pwdLength=="+pwdLength+"\n"+"pwdFormat=="+pwdFormat);
			
		}else{
			pwdTips[0].style.backgroundImage = 'url(img/green@2x.png)';
			$('#password-tips').css("display","inline");
		}
	});
}
function listenNameInput(){
	
	$('#nickname').bind('input propertychange',function(){
		var values =  $('#nickname').val();
		
		var length = values.length;
		if(length > 0){
			$('#nickname-tips').css("display","none");
			if(values.indexOf(" ") != -1){
				nameIsNull = true;
			}else{
				nameIsNull = false;
			}
			
		}else{
			$('#nickname-tips').css("display","inline");
		}
		
	});
}

function listenPhoneInput(){
	
	$('#phone').bind('input propertychange',function(){
		var values =  $('#phone').val();
		
		var length = values.length;
		var reg = /^\d*$/g;
		
		if(length > 0){
			$('#phone-tips').css("display","none");

			if(reg.test(values)){
				
				phoneIsNull = false;
				
			}else{
				console.log(reg.test(values));
				phoneIsNull = true;
			}
			
			
		}else{
			$('#phone-tips').css("display","inline");
		}
		
	});
}
/**
 * 注册界面：实时监听输入框值变化
 * 	$(id).bind("input propertychange",function}
 * 	控件bind两个事件，input propertychange，原因：oninput存在IE浏览器版本兼容问题
 * 
 */
function listenCodeInput(){
	
	$("#code").bind("input propertychange",function(){
		
		var codeVal = $("#code").val();
		var sendVal = document.getElementById("send-sms").innerHTML;
		if(codeVal == sendVal){
			$("#get_acc").css("display","block");
			console.log("1codeVal:"+codeVal+"sendVal:"+sendVal);
		}else{
			$("#get_acc").css("display","none");
			console.log("2codeVal:"+codeVal+"sendVal:"+sendVal);
		}
	});
}


		var index = 0;
		function loopImg(){
			var imgArray = ["img/1-1.jpg","img/1-3.jpg","img/1-4.jpg"];
			if(index == 4){
				index = 0;
			}
			for (var imgSrc = 0;imgSrc<imgArray.length;imgSrc++) {
				if(index == imgSrc){
					document.getElementById("sides").src = imgArray[imgSrc];
				}
			}
			index ++;
		}	
		setInterval("loopImg()",1500);

function getRanNum(){
    		
	do
		out = Math.floor(Math.random()*10000);
	while( out < 1000 )
  		document.getElementById("send-sms").innerHTML = out;
	         
}



function queryUser(){
	console.log("queryUser");
	
}

function userExist(){
	layer.alert("用户名已存在，请重新输入！！",{
		icon:2,
		skin:'layer-ext-moon',
		anim:3
	});
	
	
	
}